package cn.tedu.huntingmall.controller;

import cn.tedu.huntingmall.commons.response.JsonResult;
import cn.tedu.huntingmall.pojo.dto.user.UserLoginDTO;
import cn.tedu.huntingmall.pojo.dto.user.UserRegDTO;
import cn.tedu.huntingmall.pojo.dto.user.UserUpdatePasswordDTO;
import cn.tedu.huntingmall.pojo.vo.user.UserRegVO;
import cn.tedu.huntingmall.pojo.vo.user.UserUpdatePasswordVO;
import cn.tedu.huntingmall.service.IUserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理系统")
public class UserController {

    @Autowired
    private IUserService service;

    @PostMapping("/reg")
    @ApiOperation("用户注册")
    @ApiOperationSupport(order = 10)
    public JsonResult<UserRegVO> userReg(UserRegDTO userRegDTO){
        Long id = service.insert(userRegDTO);
        return JsonResult.ok(new UserRegVO().setId(id));
    }

    @PostMapping("/update/password")
    @ApiOperation("修改密码")
    @ApiOperationSupport(order = 30)
    public JsonResult<UserUpdatePasswordVO> userUpdatePassword(UserUpdatePasswordDTO userUpdatePasswordDTO){
        Long id = service.updatePassword(userUpdatePasswordDTO);
        return JsonResult.ok(new UserUpdatePasswordVO().setId(id));
    }

    @PostMapping("/login")
    @ApiOperation("用户登录")
    @ApiOperationSupport(order = 40)
    public JsonResult userLogin(UserLoginDTO userLoginDTO){
        int login = service.login(userLoginDTO);
        return JsonResult.ok(login);
    }

}
